/*
 * Copyright (c) 2024 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SLIDER_SLIDER_THEME_WRAPPER_H
#define FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SLIDER_SLIDER_THEME_WRAPPER_H

#include <memory>

#include "base/memory/ace_type.h"
#include "core/components/slider/slider_theme.h"
#include "core/components_ng/token_theme/token_theme_wrapper.h"

namespace OHOS::Ace::NG {

/**
 * SliderThemeWrapper defines colors and styles for Slider and Slider components
 * basing on TokenTheme's data.
 * SliderThemeWrapper should be built using SliderThemeWrapper::WrapperBuilder.
 */
class SliderThemeWrapper : public SliderTheme, public TokenThemeWrapper {
    DECLARE_ACE_TYPE(SliderThemeWrapper, SliderTheme);

public:
    class WrapperBuilder : public Builder {
    public:
        WrapperBuilder() = default;
        ~WrapperBuilder() = default;

        RefPtr<TokenThemeWrapper> BuildWrapper(const RefPtr<ThemeConstants>& themeConstants) const
        {
            auto wrapper = AceType::MakeRefPtr<SliderThemeWrapper>();
            if (!themeConstants) {
                LOGE("Build AppTheme error, themeConstants is null!");
                return wrapper;
            }
            ParsePattern(themeConstants, AceType::DynamicCast<SliderTheme>(wrapper));
            return wrapper;
        }
    };

    ~SliderThemeWrapper() override = default;

    void ApplyTokenTheme(const TokenTheme& theme) override
    {
        if (auto themeColors = theme.Colors(); themeColors) {
            trackBgColor_ = themeColors->CompBackgroundSecondary();
            trackSelectedColor_ = themeColors->BackgroundEmphasize();
            blockColor_ = themeColors->CompBackgroundPrimaryContrary();
            outsetModeSelectedTrackColor_ = themeColors->BackgroundEmphasize();
            markerColor_ = themeColors->CompBackgroundSecondary();
        }
    }

protected:
    SliderThemeWrapper() = default;
};

} // namespace
#endif